/**
 * Created with Vim7.3 ubuntu12.04
 * @fileOverview : 
 * @author : Lyle <lylechen2014@gmial.com>
 * @since : 2014-09-30 11:02:27
 * @filename : static/logic/nmm/src/views/myProfileLifeStyle.js
 * @version : 
 * @description : 
 */

define(function(require, exports, module){

    var myProfileLifeStyleView,userObj,
        mId = 'myProfileLifeStyle',reRender = false,menuName = 'myProfileLifeStyle',
        imglazyload = require('{component}imglazyload/zepto.imglazyload'),
        panel = require('{component}panel/zepto.panel'),
        tplN = require('{view}userNav.tpl'),
        tplS = require('{view}select.tpl'),
        tpl = require('{view}myProfileLifeStyle.tpl');

    myProfileLifeStyleView = Backbone.View.extend({

        template: _.template(tpl),
        templateS: _.template(tplS),
        templateN: _.template(tplN),

        bindEvt : function() {
            var tthis = this,dom = $('#'+mId);

            dom.find('.back').on('tap',function(e){
                window.location.href = '#myProfile/whole/custom2'; 
            });

            dom.find('.save').on('tap',function(e){
                var usr_id = userObj.account.usr_id;
                var obj = {
                    smoker : dom.find('#smoker').val(),
                    drinker : dom.find('#drinker').val(),
                    have_children : dom.find('#have_children').val(),
                    want_children : dom.find('#want_children').val(),
                    pets : dom.find('#have_pets').val()     
                };

                var callback = function(){
                    userObj.detail.lifestyle.smoking = obj.smoker;
                    userObj.detail.lifestyle.drinking = obj.drinker;
                    userObj.detail.lifestyle.have_children = obj.have_children;
                    userObj.detail.lifestyle.want_children = obj.want_children;
                    userObj.detail.lifestyle.have_pets = obj.pets;
                    share.cacheUserInfo(usr_id,userObj);
                    window.location.href = '#myProfile/whole/custom2'; 
                }
                share.updateProfile(usr_id,callback,obj);
            });
        },      

        render: function (obj) {
            if (!share.checkPermission(true)){return;};
            share.reRender(reRender,mId);   
            userObj = share.getObjStorage(share.userInfo().usr_id);
            if ($('#'+mId).length < 1) { 
                $('body').append(this.template(lang));
                this.bindEvt(); 
            } else {
                $('#'+mId).css('display','block');
            }
             
            share.panel(panel,this.templateN,mId,menuName);
            this.smokerRender();
            this.drinkerRender();
            this.haveChildrenRender();
            this.wantChildrenRender();
            this.havePetsRender();
        },

        smokerRender : function() {
            var select = share.getLocalStorage('ms_smoker');
            $('#'+mId).find('#smoker').html(this.templateS({obj : select, value : userObj.detail.lifestyle.smoking}));
        },

        drinkerRender : function() {
            var select = share.getLocalStorage('ms_drinker');
            $('#'+mId).find('#drinker').html(this.templateS({obj : select, value : userObj.detail.lifestyle.drinking}));

        },

        haveChildrenRender : function() {
            var select = share.getLocalStorage('ms_have_children');
            $('#'+mId).find('#have_children').html(this.templateS({obj : select, value : userObj.detail.lifestyle.have_children}));
        },

        wantChildrenRender : function() {
            var select = share.getLocalStorage('ms_want_children');
            $('#'+mId).find('#want_children').html(this.templateS({obj : select, value : userObj.detail.lifestyle.want_children}));
        },

        havePetsRender : function() {
            var select = share.getLocalStorage('ms_pets');
            $('#'+mId).find('#have_pets').html(this.templateS({obj : select, value : userObj.detail.lifestyle.have_pets}));
        },

        panel : function() {
            panel.run({
                rootDom : $('#'+mId),
                contentDom : $('#'+mId).find('.body_all')
            });
        }


	});
	module.exports = myProfileLifeStyleView;
})

